<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Blog</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/blog/favicon.ico">
    <meta name="description" content="MyBlog">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog/assets/css/0.styles.61da7a09.css" as="style"><link rel="preload" href="/blog/assets/js/app.c8bfb5c3.js" as="script"><link rel="preload" href="/blog/assets/js/3.08e74d92.js" as="script"><link rel="preload" href="/blog/assets/js/1.f96517fa.js" as="script"><link rel="preload" href="/blog/assets/js/16.261be55c.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.14d8e5c7.js"><link rel="prefetch" href="/blog/assets/js/11.a1a32059.js"><link rel="prefetch" href="/blog/assets/js/12.83c03cbb.js"><link rel="prefetch" href="/blog/assets/js/13.46ffbb28.js"><link rel="prefetch" href="/blog/assets/js/14.f20a4faf.js"><link rel="prefetch" href="/blog/assets/js/15.30235eae.js"><link rel="prefetch" href="/blog/assets/js/17.d7282b69.js"><link rel="prefetch" href="/blog/assets/js/18.e8bca3cd.js"><link rel="prefetch" href="/blog/assets/js/19.663ba2bd.js"><link rel="prefetch" href="/blog/assets/js/20.5d2b0628.js"><link rel="prefetch" href="/blog/assets/js/21.e9d43c16.js"><link rel="prefetch" href="/blog/assets/js/4.6ccf2801.js"><link rel="prefetch" href="/blog/assets/js/5.d9c29fca.js"><link rel="prefetch" href="/blog/assets/js/6.510ee365.js"><link rel="prefetch" href="/blog/assets/js/7.79ac4d06.js"><link rel="prefetch" href="/blog/assets/js/8.ddfc50a4.js"><link rel="prefetch" href="/blog/assets/js/9.0724da36.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.61da7a09.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-7dd95ae2><div data-v-7dd95ae2><div class="password-shadow password-wrapper-out" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>Blog</h3> <p class="description" data-v-59e6cb88>MyBlog</p> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>Brod-Roy</span>
          
        <!---->
        2022
      </a></span></div></div> <div class="hide" data-v-7dd95ae2><header class="navbar" data-v-7dd95ae2><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/logo.png" alt="Blog" class="logo"> <span class="site-name">Blog</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/frontEnd/" class="nav-link"><i class="undefined"></i>
  frontEnd
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间索引
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      相关内容
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/Brod_Roy" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-7dd95ae2></div> <aside class="sidebar" data-v-7dd95ae2><div class="personal-info-wrapper" data-v-1fad0c41 data-v-7dd95ae2><img src="/blog/avatar.jpg" alt="author-avatar" class="personal-img" data-v-1fad0c41> <h3 class="name" data-v-1fad0c41>
    Brod-Roy
  </h3> <div class="num" data-v-1fad0c41><div data-v-1fad0c41><h3 data-v-1fad0c41>1</h3> <h6 data-v-1fad0c41>Articles</h6></div> <div data-v-1fad0c41><h3 data-v-1fad0c41>2</h3> <h6 data-v-1fad0c41>Tags</h6></div></div> <ul class="social-links" data-v-1fad0c41></ul> <hr data-v-1fad0c41></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/frontEnd/" class="nav-link"><i class="undefined"></i>
  frontEnd
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间索引
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      相关内容
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/Brod_Roy" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88></h3> <!----> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>Brod-Roy</span>
          
        <!---->
        2022
      </a></span></div></div> <div data-v-7dd95ae2><div data-v-7dd95ae2><main class="page" style="padding-right:0;"><section style="display:;"><div class="page-title"><h1 class="title"></h1> <div data-v-8a445198><i class="iconfont reco-account" data-v-8a445198><span data-v-8a445198>Brod-Roy</span></i> <!----> <!----> <!----></div></div> <div class="theme-reco-content content__default"><p>---</p> <p>title: TypeError: uni.onWindowResize 监听窗口尺寸变化事件</p> <p>date: 2022-12-12</p> <p>categories:</p> <p>- 前端学习</p> <p>tags:</p> <p>- uniapp</p> <p>---</p> <h1 id="uni-onwindowresize-监听窗口尺寸变化事件"><a href="#uni-onwindowresize-监听窗口尺寸变化事件" class="header-anchor">#</a> uni.onWindowResize 监听窗口尺寸变化事件</h1> <blockquote><p>官方介绍是监听窗口尺寸变化事件（1.6.0 新增），听起来只能监听一下页面的宽高，实际上在 uniapp 中可以用 <code>uni.onWindowResize(CALLBACK)</code> 事件监听到页面的屏幕宽高和当前设备的横竖屏状态</p> <p>官方文档：<a href="https://uniapp.dcloud.net.cn/api/ui/window.html#onwindowresize" target="_blank" rel="noopener noreferrer">uni.onWindowResize(CALLBACK)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <blockquote><p>PS：本文会比官方文档更详细</p></blockquote></blockquote> <h2 id="uni-onwindowresize-callback"><a href="#uni-onwindowresize-callback" class="header-anchor">#</a> uni.onWindowResize(CALLBACK)</h2> <blockquote><p>监听窗口尺寸变化事件（1.6.0 新增）</p></blockquote> <h3 id="各平台支持说明"><a href="#各平台支持说明" class="header-anchor">#</a> 各平台支持说明</h3> <table><thead><tr><th style="text-align:center;">App</th> <th style="text-align:center;">H5</th> <th style="text-align:center;">微信小程序</th> <th style="text-align:center;">支付宝小程序</th> <th style="text-align:center;">百度小程序</th> <th style="text-align:center;">字节跳动小程序</th> <th style="text-align:center;">飞书小程序</th></tr></thead> <tbody><tr><td style="text-align:center;">√</td> <td style="text-align:center;">√</td> <td style="text-align:center;">√</td> <td style="text-align:center;">x</td> <td style="text-align:center;">x</td> <td style="text-align:center;">x</td> <td style="text-align:center;">√</td></tr></tbody></table> <h3 id="callback-参数说明"><a href="#callback-参数说明" class="header-anchor">#</a> <strong>CALLBACK 参数说明</strong></h3> <table><thead><tr><th>属性</th> <th>类型</th> <th>说明</th></tr></thead> <tbody><tr><td>size</td> <td>Object</td> <td>变化后的窗口的大小，单位为 px ，{windowWidth,windowHeight,screenHeight,screenWidth}</td></tr> <tr><td>deviceOrientation</td> <td>String</td> <td>当前屏幕所处的状态，portrait 竖屏 landscape 横屏</td></tr></tbody></table> <h3 id="官方代码示例"><a href="#官方代码示例" class="header-anchor">#</a> 官方代码示例</h3> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">const</span> <span class="token function-variable function">windowResizeCallback</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'变化后的窗口宽度='</span> <span class="token operator">+</span> res<span class="token punctuation">.</span>size<span class="token punctuation">.</span>windowWidth<span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'变化后的窗口高度='</span> <span class="token operator">+</span> res<span class="token punctuation">.</span>size<span class="token punctuation">.</span>windowHeight<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
uni<span class="token punctuation">.</span><span class="token function">onWindowResize</span><span class="token punctuation">(</span>windowResizeCallback<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="个人示例代码"><a href="#个人示例代码" class="header-anchor">#</a> 个人示例代码</h3> <blockquote><p>有一点需要注意的就是，<code>uni.onWindowResize</code> 必须放在 onShow() 里面，否则无法做到触发监听。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
	<span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token punctuation">{</span>
			<span class="token literal-property property">windowResizeCallback</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token function">onLoad</span><span class="token punctuation">(</span><span class="token parameter">option</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token function">onShow</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 声明回调函数是为了控制取消监听，不取消也可以直接写在函数内部就好</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function-variable function">windowResizeCallback</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
			console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'onWindowResize'</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		uni<span class="token punctuation">.</span><span class="token function">onWindowResize</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>windowResizeCallback<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token literal-property property">methods</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h3 id="tips"><a href="#tips" class="header-anchor">#</a> <strong>TIPS</strong></h3> <ul><li><p>如App端设置软键盘弹出方式为adjustResize ，则在键盘弹出时，会触发此事件。</p></li> <li><p>横竖屏切换时，会触发此事件：</p> <blockquote><blockquote><p>在小程序中会默认竖屏状态，开启横竖屏旋转需要在 pages.json 中进行配置:</p></blockquote> <p><strong>单页面配置旋转</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token string-property property">&quot;pages&quot;</span><span class="token operator">:</span> 
<span class="token punctuation">[</span><span class="token punctuation">{</span>
	<span class="token string-property property">&quot;path&quot;</span><span class="token operator">:</span> <span class="token string">&quot;pages/tabBar/home/home&quot;</span><span class="token punctuation">,</span>
	<span class="token string-property property">&quot;style&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
		<span class="token string-property property">&quot;navigationStyle&quot;</span><span class="token operator">:</span> <span class="token string">&quot;custom&quot;</span><span class="token punctuation">,</span>
		<span class="token string-property property">&quot;enablePullDownRefresh&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        <span class="token string-property property">&quot;pageOrientation&quot;</span><span class="token operator">:</span> <span class="token string">&quot;auto&quot;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><strong>全局页面配置旋转</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token string-property property">&quot;globalStyle&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
	<span class="token string-property property">&quot;navigationBarTextStyle&quot;</span><span class="token operator">:</span> <span class="token string">&quot;black&quot;</span><span class="token punctuation">,</span>
	<span class="token string-property property">&quot;navigationBarBackgroundColor&quot;</span><span class="token operator">:</span> <span class="token string">&quot;#ffffff&quot;</span><span class="token punctuation">,</span>
	<span class="token string-property property">&quot;backgroundColor&quot;</span><span class="token operator">:</span> <span class="token string">&quot;#ffffff&quot;</span><span class="token punctuation">,</span>
    <span class="token string-property property">&quot;pageOrientation&quot;</span><span class="token operator">:</span> <span class="token string">&quot;auto&quot;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div></blockquote></li></ul> <h2 id="uni-offwindowresize-callback"><a href="#uni-offwindowresize-callback" class="header-anchor">#</a> uni.offWindowResize(CALLBACK)</h2> <blockquote><p>取消监听窗口尺寸变化事件（1.6.0 新增）</p></blockquote> <h3 id="各平台支持情况"><a href="#各平台支持情况" class="header-anchor">#</a> 各平台支持情况</h3> <table><thead><tr><th style="text-align:center;">App</th> <th style="text-align:center;">H5</th> <th style="text-align:center;">微信小程序</th> <th style="text-align:center;">支付宝小程序</th> <th style="text-align:center;">百度小程序</th> <th style="text-align:center;">字节跳动小程序</th> <th style="text-align:center;">飞书小程序</th></tr></thead> <tbody><tr><td style="text-align:center;">√</td> <td style="text-align:center;">√</td> <td style="text-align:center;">√</td> <td style="text-align:center;">x</td> <td style="text-align:center;">x</td> <td style="text-align:center;">x</td> <td style="text-align:center;">√</td></tr></tbody></table> <h3 id="tips-2"><a href="#tips-2" class="header-anchor">#</a> Tips</h3> <ul><li><p><code>CALLBACK</code>为调用<code>uni.onWindowResize</code>时传入的<code>CALLBACK</code></p> <blockquote><p>也就是为什么在上面要声明一个变量</p></blockquote></li></ul> <h3 id="代码示例"><a href="#代码示例" class="header-anchor">#</a> 代码示例</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
	<span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token punctuation">{</span>
			<span class="token literal-property property">windowResizeCallback</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token function">onLoad</span><span class="token punctuation">(</span><span class="token parameter">option</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token function">onShow</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function-variable function">windowResizeCallback</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
			console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'onWindowResize'</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		uni<span class="token punctuation">.</span><span class="token function">onWindowResize</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>windowResizeCallback<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 声明后就可以直接阻止事件触发了</span>
        uni<span class="token punctuation">.</span><span class="token function">offWindowResize</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>windowResizeCallback<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token literal-property property">methods</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div></div></section> <footer class="page-edit"><!----> <!----></footer> <!----> <div class="comments-wrapper"><!----></div></main></div> <!----></div> <ul class="sub-sidebar sub-sidebar-wrapper" style="width:0;" data-v-b57cc07c data-v-7dd95ae2></ul></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/blog/assets/js/app.c8bfb5c3.js" defer></script><script src="/blog/assets/js/3.08e74d92.js" defer></script><script src="/blog/assets/js/1.f96517fa.js" defer></script><script src="/blog/assets/js/16.261be55c.js" defer></script>
  </body>
</html>
